package com.entertainment.ticketing.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "ticket_info",
        uniqueConstraints = {
                @UniqueConstraint(name = "uk_seat", columnNames = {"event_id", "seat_area", "seat_row", "seat_number"})
        },
        indexes = {
                @Index(name = "idx_event_id", columnList = "event_id"),
                @Index(name = "idx_status", columnList = "status"),
                @Index(name = "idx_ticket_type", columnList = "ticket_type")
        })
public class TicketInfo {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(optional = false)
    @JoinColumn(name = "event_id", nullable = false,
            foreignKey = @ForeignKey(name = "fk_ticket_event"))
    private EventInfo event;

    @Column(name = "ticket_type", nullable = false, length = 50)
    private String ticketType; // VIP/PREMIUM/STANDARD

    @Column(nullable = false, precision = 10, scale = 2)
    private BigDecimal price;

    @Column(name = "seat_area", length = 50)
    private String seatArea;

    @Column(name = "seat_row", length = 10)
    private String seatRow;

    @Column(name = "seat_number", length = 10)
    private String seatNumber;

    @Column(nullable = false)
    private Byte status = 1; // 1-可售，2-已售，3-锁定，0-不可售

    @CreationTimestamp
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;

    @UpdateTimestamp
    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt;
}